﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=50",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "../system/error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab = tabs.getTab("tab$50");
                    tabs.removeTab(tab);
                }
            }
        });
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom:0;">
        <table>
            <tr>
                <td>
                    类型: 其他问题
                    <input class="mini-hidden" name="type" id="type" value="7"/>
                    <a class="mini-button" iconCls="icon-search" plain="true" onclick="search()">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-remove" plain="true" onclick="delRows()">删除</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit" >
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetConsultList" sizeList="[15,20,50,100]" pageSize="15">
            <div property="columns">
                <div type="checkcolumn">
                </div>
                <div cellCls="actionIcons" name="action" width="60px" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
                <div field="cs_asker" width="100px" headeralign="center" align="center" allowsort="true">
                    提问人</div>
                <div field="cs_content" width="250px" headeralign="center" align="center" allowsort="true">
                    内容</div>
                <div field="cs_tel" width="100px" headeralign="center" align="center" allowsort="true">
                    联系电话</div>
                <div field="cs_email" width="100px" headeralign="center" align="center" allowsort="true">
                    电子邮件</div>
                <div field="cs_hide" width="100px" headeralign="center" align="center" allowsort="true" renderer="onHideRenderer">
                    处理结果</div>
                <div field="cs_asktime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">
                    提问时间</div>
                <div field="cs_askip" width="70px" headeralign="center" align="center" allowsort="true">
                    提问IP</div>
                <div field="cs_hftime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">
                    回复时间</div>
                <div field="cs_hfcontent" width="250px" headeralign="center" align="center" allowsort="true">
                    回复</div>
            </div>
        </div>
    </div>
    <div id="editWindow" class="mini-window" title="咨询回复" style="width:580px;" showModal="true" allowResize="false" allowDrag="true" showFooter="true">
        <div id="editform" class="form">
            <input class="mini-hidden" name="cs_no" />
            <table style="width:96%;">
                <tr>
                    <td class="tdtitle" style="width:70px;">提问人：</td>
                    <td class="tdtext" colspan="3" id="name"></td>
                </tr>
                <tr>
                    <td class="tdtitle">联系方式：</td>
                    <td class="tdtext" colspan="3" id="phone"></td>
                </tr>
                <tr>
                    <td class="tdtitle">问题内容：</td>
                    <td class="tdtext" colspan="3" id="content"></td>
                </tr>
                <tr>
                    <td class="tdtitle">回复内容：</td>
                    <td class="tdtext" colspan="3"><input class="mini-textarea" name="cs_hfcontent" style="width:440px;height:100px"  /></td>
                </tr>
            </table>
        </div>
        <div property="footer" style="text-align:center;padding:5px;">
            <a class="mini-button" style="width:60px;" onclick="updateRow()">保存</a>
            <span style="display:inline-block;width:25px;"></span>
            <a class="mini-button" style="width:60px;" onclick="closewin()">关闭</a>
        </div>
    </div>
</body>
<script type="text/javascript">
    $.ajaxSetup({
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        complete: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.responseText == "out") {
                var loginWindow = parent.mini.get("loginWindow");
                if (!loginWindow.visible)
                    loginWindow.show();
            }
        }
    });

    mini.parse();

    var grid = mini.get("datagrid1");
    search();

    function search() {
        var type = mini.get("type").getValue();
        grid.load({ type: type });
        grid.sortBy("cs_no", "desc");
    }

    function onActionRenderer(e) {
        var record = e.record;
        var s = '<span class="icon-edit actionspan" title="回复" onclick="editRow(' + record._uid + ')"></span><span class="separator"></span><span class="icon-remove actionspan" title="删除" onclick="delRow(' + record._uid + ')"></span>';
        return s;
    }

    function onHideRenderer(e) {
        var s;
        if (e.value != null && e.value > 0)
            s = '<font color="Red">隐藏</font>';
        else
            s = '<font color="Blue">公开</font>';
        return s;
    }

    function editRow(row_uid) {
        var row = grid.getRowByUID(row_uid);
        if (row) {
            var win = mini.get("editWindow");
            var form = new mini.Form("#editform");
            form.clear();
            form.loading();
            $.ajax({
                url: "../data/system.aspx?method=GetConsult",
                data: { id: row.cs_no },
                success: function (text) {
                    form.unmask();
                    if (text == "out") {
                        win.hide();
                        var loginWindow = parent.mini.get("loginWindow");
                        if (!loginWindow.visible)
                            loginWindow.show();
                        return;
                    }
                    var o = mini.decode(text);
                    $("#name").html(o.cs_asker + "&nbsp;&nbsp;(" + mini.formatDate(o.cs_asktime, 'yyyy-MM-dd HH:mm:ss') + "&nbsp;&nbsp;IP:" + o.cs_askip + ")&nbsp;&nbsp;处理结果：" + (o.cs_hide == 0 ? '显示' : '<font style="color:red">隐藏</font>'));
                    $("#phone").html(o.cs_tel + "&nbsp;&nbsp;&nbsp;&nbsp;" + (o.cs_email == null ? "" : o.cs_email));
                    $("#content").html(o.cs_content);
                    form.setData(o);
                    win.show();
                },
                error: function () {
                    form.unmask();
                    ShowMessage("系统提示", "表单加载出错！", 3);
                }
            });
        }
    }

    function updateRow() {
        var form = new mini.Form("#editform");
        form.validate();
        if (form.isValid() == false)
            return;
        var o = form.getData();
        var json = mini.encode(o);

        mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });
        $.ajax({
            url: "../data/system.aspx?method=SaveConsult",
            data: { data: json },
            type: "post",
            success: function (ret) {
                mini.unmask(document.body);
                if (ret == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    return;
                }
                var editWindow = mini.get("editWindow");
                if (ret == 1) {
                    editWindow.hide();
                    ShowMessage("系统提示", "回复成功！", 1);
                    search();
                }
                else if (ret == 0) {
                    editWindow.hide();
                    ShowMessage("系统提示", "该咨询已不存在，请确认！", 2);
                    search();
                }
                else
                    ShowMessage("系统提示", "回复失败！", 3);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                mini.unmask(document.body);
                ShowMessage("系统提示", "回复失败！", 3);
            }
        });
    }

    function closewin() {
        var win = mini.get("editWindow");
        var form = new mini.Form("#editform");
        form.clear();
        if (win.visible)
            win.hide();
    }

    function delRow(row_uid) {
        var row = grid.getRowByUID(row_uid);
        if (row) {
            mini.confirm("确定删除此咨询吗？", "系统提示",
                function (action) {
                    if (action == "ok") {
                        mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                        $.ajax({
                            url: "../data/system.aspx?method=DeleteConsult",
                            data: { id: row.cs_no },
                            success: function (ret) {
                                mini.unmask(document.body);
                                if (ret == "out") {
                                    var loginWindow = parent.mini.get("loginWindow");
                                    if (!loginWindow.visible)
                                        loginWindow.show();
                                    return;
                                }
                                if (ret >= 0) {
                                    ShowMessage("系统提示", "咨询删除成功！", 1);
                                    search();
                                }
                                else
                                    ShowMessage("系统提示", "咨询删除失败！", 3);
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                mini.unmask(document.body);
                                ShowMessage("系统提示", "咨询删除失败！", 3);
                            }
                        });
                    }
                }
            );
        }
    }

    function delRows() {
        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            mini.confirm("确定删除所选咨询吗？", "系统提示",
                function (action) {
                    if (action == "ok") {
                        mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                        var ids = "";
                        for (var i = 0; i < rows.length; i++) {
                            ids += rows[i].cs_no + ',';
                        }

                        $.ajax({
                            url: "../data/system.aspx?method=DeleteConsult",
                            type: "post",
                            data: { id: ids },
                            success: function (ret) {
                                mini.unmask(document.body);
                                if (ret == "out") {
                                    var loginWindow = parent.mini.get("loginWindow");
                                    if (!loginWindow.visible)
                                        loginWindow.show();
                                    return;
                                }
                                if (ret >= 0) {
                                    ShowMessage("系统提示", "咨询删除成功！", 1);
                                    grid.reload();
                                }
                                else
                                    ShowMessage("系统提示", "咨询删除失败！", 3);
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                mini.unmask(document.body);
                                ShowMessage("系统提示", "咨询删除失败！", 3);
                            }
                        });
                    }
                }
            );
        } else
            ShowMessage("系统提示", "请选择需要删除的咨询！", 2);
    }
</script>
</html>